PHP strtotime() 函數(shù)
定義和用法
strtotime() 函數(shù)將任何英文文本的日期時間描述解析為 Unix 時間戳。
語法
strtotime(time,now)
參數(shù) | 描述 |
---|---|
time | 規(guī)定要解析的時間字符串。 |
now | 用來計算返回值的時間戳。如果省略該參數(shù),則使用當前時間。 |
說明
該函數(shù)預期接受一個包含美國英語日期格式的字符串并嘗試將其解析為 Unix 時間戳(自 January 1 1970 00:00:00 GMT 起的秒數(shù)),其值相對于 now 參數(shù)給出的時間,如果沒有提供此參數(shù),則用系統(tǒng)當前時間。
該函數(shù)將使用 TZ 環(huán)境變量(如果有的話)來計算時間戳。自 PHP 5.1.0 起有更容易的方法來定義時區(qū)用于所有的日期/時間函數(shù)。此過程在 date_default_timezone_get() 函數(shù)頁面中有說明。
返回值
成功則返回時間戳,否則返回 FALSE。在 PHP 5.1.0 之前本函數(shù)在失敗時返回 -1。
例子
<?php echo(strtotime("now")); echo(strtotime("3 October 2005")); echo(strtotime("+5 hours")); echo(strtotime("+1 week")); echo(strtotime("+1 week 3 days 7 hours 5 seconds")); echo(strtotime("next Monday")); echo(strtotime("last Sunday")); ?>
輸出:
1138614504 1128290400 1138632504 1139219304 1139503709 1139180400 1138489200